{-# LANGUAGE ViewPatterns #-}
-----------------------------------------------------------------------------
--
-- Module      :  LLVM.Code.Instructions.Binary
-- Copyright   :  Mikhail Belyaev
-- License     :  GPL (Just (Version {versionBranch = [3], versionTags = []}))
--
-- Maintainer  :
-- Stability   :
-- Portability :
--
-- |
--
-----------------------------------------------------------------------------

module LLVM.Code.Instructions.Binary where


import LLVM.Code.Shared (ValIndex(..))
import LLVM.Code.Shared (TypeIndex(..))
import LLVM.Code.Shared (BinOpcode(..))
import LLVM.Parser.Record.Record (recordAsList, RecordType(..))

import LLVM.Util
import Data.Maybe (fromJust, isJust)
import LLVM.Code.Types (Type)
import LLVM.Code.Instructions.Class (BuildableInstruction(..))
import LLVM.Code.Instructions.Util
       (Matched(..), Matcher(..), matchRRwithCode)
import LLVM.Code.Instructions.Values (BinaryInstruction(..))



instance BuildableInstruction BinaryInstruction where
    buildInstruction rr tt vt =
        case (matchRRwithCode tt vt [MValueTypePair, MValue, MInteger] 2 rr) of
             [MdValueTypePair (v1,ty), MdValue v2 , MdInteger (integerToIC -> Just bopc)] ->
                    Just BinaryInstruction{
                        biOpcode = bopc,
                        biType = ty,
                        biOp1 = v1,
                        biOp2 = v2
                    }
             _ -> Nothing


